package cn.boy.gui.student;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import cn.boy.domain.Student;
import cn.boy.gui.adminstrator.AdminInfoActivity;
import cn.boy.gui.adminstrator.AdminInfoEditActivity;
import cn.boy.home.HomeApplication;
import cn.boy.home.R;

public class StudentInfoActivity extends Activity {
	
	HomeApplication app;
	
	TextView txtNO;
	TextView txtName;
	TextView txtAge;
	TextView txtSex;
	TextView txtDorm;
	TextView txtClassInfo;
	
	Button editButton;
	
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.student_info);
		
		findViews();
		
		app = (HomeApplication) getApplicationContext();
		
		
		initInfo();
		
		if(app.isFlag()){
			editButton.setVisibility(View.VISIBLE);
		}
		editButton.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				Intent intent = new Intent(StudentInfoActivity.this,StudentInfoEditActivity.class);
				startActivity(intent);
				finish();
			}
		});
	}

	private void initInfo() {
		Student student = app.getStudent();
		txtNO.setText(student.getNO());
		txtName.setText(student.getName());
		txtAge.setText(student.getAge());
		txtSex.setText(student.getSex());
		txtDorm.setText(student.getDormitoryNO());
		txtClassInfo.setText(student.getClassInfo());
		
	}

	private void findViews() {

		txtNO = (TextView)findViewById(R.id.tv_student_no);
		txtName = (TextView)findViewById(R.id.tv_student_name);
		txtAge = (TextView)findViewById(R.id.tv_student_age);
		txtSex = (TextView)findViewById(R.id.tv_student_sex);
		txtDorm = (TextView)findViewById(R.id.tv_student_dorm);
		txtClassInfo = (TextView)findViewById(R.id.tv_student_class);
		
		editButton = (Button)findViewById(R.id.btn_edit);
		
	}
}
